package main

import (
	"fmt"
	"github.com/panjf2000/ants/v2"
	"go.uber.org/zap"
	"lz/config"
	"os"
	"os/signal"

	"syscall"

	"lz/global"
	"lz/initialize"
)

func main() {

	//1初始化日志
	initialize.InitLog()

	//1. 初始化配置文件
	initialize.InitConfig()

	//2. 初始化routers
	Router := initialize.Routers()

	//3. 初始化翻译
	if err := initialize.InitTrans("zh"); err != nil {
		panic(err)
	}

	//4.初始化规则
	config.InitConfig()
	//initialize.InitDb()

	//5.初始化redis
	initialize.RedisPool()

	//6初始化推送消息
	initialize.InitPush()

	//7启动协程序池
	pool, err := ants.NewPool(10000, ants.WithDisablePurge(true), ants.WithExpiryDuration(1))
	if err != nil {
		panic(err)
	}
	global.AntsPool = pool

	//8 初始化定时器
	go func() {
		initialize.InitTimer()
	}()

	//9 启动终止服务
	go func() {

		//启动gin 路由
		if err := Router.Run(fmt.Sprintf(":%d", global.ServerConfig.Port)); err != nil {
			zap.S().Errorf("启动失败:%v", err)
		}
		zap.S().Infof("端口号:%v,启动成功", global.ServerConfig.Port)

	}()

	//接收终止信号
	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)

	<-quit

}
